<?php

namespace App\Http\Controllers\Service;

use App\Tool\Validate\ValidateCode;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use App\Tool\SMS\SendTemplateSMS;
use App\Entity\Temp_phone;
use App\Models\M3Result;

class ValidateController extends Controller
{
   public function create($value = ''){

       $validateCode = new ValidateCode;
       return $validateCode->doimg();
   }

    public function sendSMS(Request $request){
        $M3Result = new M3Result;
        $phone=$request->input('phone','');
        if($phone == ''){
            $M3Result->status = 1;
            $M3Result->message = '手机号不能为空';
            return $M3Result->toJson();
        }
        $code = null;
        $SendTemplateSMS = new SendTemplateSMS;
        error_reporting(E_ALL);
        ini_set( 'display_errors', 'On' );

        $charsert = '0123456789';
        $_len = strlen($charsert)-1;
        for($i=0;$i<4;$i++){
            $code .=$charsert[mt_rand(0,$_len)];
        }$SendTemplateSMS->sendTemplateSMS($phone,array($code,'60'),'1');
         //把数据存进临时表Temp_phone->phone
        $Temp_phone = new Temp_phone;
        $Temp_phone->phone = $phone;
        $Temp_phone->code = $code;
        $Temp_phone->deadline = date('Y-m-d H-i-s',time()+60 *60);
        $Temp_phone->save();
        $M3Result->status = 0;
        $M3Result->message = '发送成功';
        return $M3Result->toJson();


    }
}
